*File: div_gov_analysis_ssh.do
*Purpose: Data Analysis for Divided Government Paper

clear all
set more off

cap cd "~/div_gov"

*Load formatted data

use "data/congress_data.dta", clear

*Check mean levels of total and significant acts by "era" (pre/post 1900)
sum sigact_n pub_acts if congress<=55
sum sigact_n pub_acts if congress>55

*Summary Statistics

*Table 1
*Create Table of Significant and Total Legislation made Under Divided Gov and Unified Gov.
gen sigact_n_sd = sigact_n
gen pub_acts_sd = pub_acts

collapse (mean) sigact_n pub_acts (sd) sigact_n_sd pub_acts_sd (count) priv_acts, by(unified_g)

outsheet using "figs_ssh/table1.csv", comma replace

*Table 2

use "data/congress_data.dta", clear

*Generate Unified Gov Dummy Variable
gen unified = "Divided" if unified_g == 0
replace unified = "Unified" if unified_g == 1

collapse (mean) sigact_n pub_acts (count) priv_acts, by(period unified)
rename priv_acts obs
outsheet using "figs_ssh/table2.csv", comma replace


*Table 3
use "data/congress_data.dta", clear

*Select Decade to omit (Use first Congress as base line?)
char decade[omit] 1780

gen time = congress
gen time_2 = time^2

label var time "Time"
label var time_2 "Time Squared"

local spec1 unified_g
local spec2 `spec1' i.period
local spec3 `spec2' i.president
local spec4 `spec2' i.decade

forvalues n = 1(1)4{
xi: reg pub_acts `spec`n'', robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'', robust
estimates store sig_`n'

xi: reg ln_pub_acts `spec`n'', robust
estimates store ln_pub_`n'
xi: reg ln_sigact_n `spec`n'', robust
estimates store ln_sig_`n'
}

esttab pub* sig* using "figs_ssh/table3.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output \label{tab3}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab pub* sig* using "figs_ssh/table3.csv", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output \label{tab3}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0)) nomtitles replace

esttab ln_pub* ln_sig* using "figs_ssh/table3log.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) ///
addnotes("Robust Standard Errors" "We transformed the outcome variable for log(Significant Legislation) by adding" "one to address the one instance where a Congress produced no significant legislation.") ///
r2 se compress title("Divided/Unified Government and log(Legislative Output) \label{tab3log}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("log(Total Legislation)" "log(Significant Legislation)", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab ln_pub* ln_sig* using "figs_ssh/table3log.csv", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) ///
addnotes("Robust Standard Errors" "We transformed the outcome variable for log(Significant Legislation) by adding" "one to address the one instance where a Congress produced no significant legislation.") ///
r2 se compress title("Divided/Unified Government and log(Legislative Output) \label{tab3log}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("log(Total Legislation)" "log(Significant Legislation)", pattern(1 0 0 0 1 0 0 0)) nomtitles replace


*Additional Figures for Presentation

esttab pub* using "figs_ssh/table3pub.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output (Total Legislation) \label{tab3pub}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab sig_2 sig_3 sig_4 using "figs_ssh/table3sig.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output (Significant Legislation) \label{tab3sig}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Significant Legislation", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*APPENDIX TABLE FOR PRE AND POST 1900

forvalues n = 1(1)4{
xi: reg pub_acts `spec`n'' if congress<=55, robust
estimates store pre_pub_`n'
xi: reg sigact_n `spec`n'' if congress<=55, robust
estimates store pre_sig_`n'

xi: reg pub_acts `spec`n'' if congress>55, robust
estimates store post_pub_`n'
xi: reg sigact_n `spec`n'' if congress>55, robust
estimates store post_sig_`n'
}

esttab pre_pub* pre_sig* using "figs_ssh/table3_1_55.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output, Before 1900 \label{tab3a}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab post_pub* post_sig* using "figs_ssh/table3_56_111.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output, 1900 and After \label{tab3b}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*APPENDIX TABLE THAT INCLUDES SPEC WITH TIME TREND
local spec1 unified_g
local spec2 `spec1' time time_2
local spec3 `spec2' i.president
local spec4 `spec2' i.decade

forvalues n = 1(1)4{
xi: reg pub_acts `spec`n'', robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'', robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/table_app_time_trend.tex", b(%9.2f) label ///
indicate("Time Trend (Polynomial) = time" "President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output with Time Trend \label{tabtimetrend}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab pub* sig* using "figs_ssh/table_app_time_trend.csv", b(%9.2f) label ///
indicate("Time Trend (Polynomial) = time" "President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output with Time Trend \label{tabtimetrend}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0)) nomtitles replace

estimates clear

*Appendix Table
*Test of patterns w/ in Unified Gov

foreach var of varlist  time_since* {
gen ln_`var' = log(`var')
}

label var ln_time_since_unif "log(Time Since Pres. Party Held Unified Control)"
label var ln_time_since_unif_opp "log(Time Since Party Opposing Pres. Held Unified Control)"
label var ln_time_since_div "log(Time Since Divided Government)"

local spec1 ln_time_since_unif ln_time_since_unif_opp ln_time_since_div //house_maj_pct sen_maj_pct
local spec2 `spec1' i.period

forvalues n = 1(1)2{
xi: reg pub_acts `spec`n'' if unified_g == 1, robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'' if unified_g == 1, robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/table_app.tex", b(%9.2f) indicate("Time Period Controls = _Iperiod*" ) ///
drop(_cons ) addnotes("Robust Standard Errors" ) label r2 se compress title("Determinants of Productivity under Unified Government \label{tabdet}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab pub* sig* using "figs_ssh/table_app.csv", b(%9.2f) indicate("Time Period Controls = _Iperiod*" ) ///
drop(_cons ) addnotes("Robust Standard Errors" ) label r2 se compress title("Determinants of Productivity under Unified Government \label{tabdet}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0)) nomtitles replace

estimates clear

*Table 4
use "data/congress_data.dta", clear
 
tsset congress

local specb1 d_u_g
local specb2 `specb1' L.d_pubact
local specb3 `specb1' i.period

local specc1 d_u_g
local specc2 `specb1' L.d_sigact
local specc3 `specc1' i.period

local ln_specb1 d_u_g
local ln_specb2 `ln_specb1' L.ln_d_pubact
local ln_specb3 `ln_specb1' i.period

local ln_specc1 d_u_g
local ln_specc2 `ln_specb1' L.ln_d_sigact
local ln_specc3 `ln_specc1' i.period

forvalues n = 1(1)3{
xi: reg d_pubact `specb`n'', robust
estimates store pub_`n'
xi: reg d_pubact `specb`n'' if congress<=55, robust
estimates store pre_pub_`n'
xi: reg d_pubact `specb`n'' if congress>55, robust
estimates store post_pub_`n'

xi: reg ln_d_pubact `ln_specb`n'', robust
estimates store ln_pub_`n'
xi: reg ln_d_pubact `ln_specb`n'' if congress<=55, robust
estimates store ln_pre_pub_`n'
xi: reg ln_d_pubact `ln_specb`n'' if congress>55, robust
estimates store ln_post_pub_`n'
}

forvalues n = 1(1)3{
xi: reg d_sigact `specc`n'', robust
estimates store sig_`n'
xi: reg d_sigact `specc`n'' if congress<=55, robust
estimates store pre_sig_`n'
xi: reg d_sigact `specc`n'' if congress>55, robust
estimates store post_sig_`n'

xi: reg ln_d_sigact `ln_specc`n'', robust
estimates store ln_sig_`n'
xi: reg ln_d_sigact `ln_specc`n'' if congress<=55, robust
estimates store ln_pre_sig_`n'
xi: reg ln_d_sigact `ln_specc`n'' if congress>55, robust
estimates store ln_post_sig_`n'
}

esttab pub* sig* using "figs_ssh/table4.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and Legislative Output \label{tab4}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ Total Legislation" "$\Delta$ Significant Legislation", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab pre_pub* pre_sig* using "figs_ssh/table4_1_55.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and Legislative Output, Before 1900 \label{tab4a}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ Total Legislation" "$\Delta$ Significant Legislation", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab post_pub* post_sig* using "figs_ssh/table4_56_111.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and Legislative Output, 1900 and After \label{tab4b}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ Total Legislation" "$\Delta$ Significant Legislation", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab ln_pub* ln_sig* using "figs_ssh/table4log.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output) \label{tab4log}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab ln_pre_pub* ln_pre_sig* using "figs_ssh/table4log_1_55.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output), Before 1900 \label{tab4alog}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab ln_post_pub* ln_post_sig* using "figs_ssh/table4log_56_111.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output), 1900 and After \label{tab4blog}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*More Appendix Tables 
*(Supermajorities)

use "data/congress_data.dta", clear

gen super_unif = unified_g * supermajority
label var super_unif "Unified Government x Supermajority"

local spec1 unified_g supermajority super_unif
local spec2 `spec1' i.period

forvalues n = 1(1)2{
xi: reg pub_acts `spec`n'' if year>=1917, robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'' if year>=1917, robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/supermaj_table.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g supermajority super_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, Senate Supermajorities and Legislative Output, 1917-2010 \label{tabsupermaj}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab pub* sig* using "figs_ssh/supermaj_table.csv", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g supermajority super_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, Senate Supermajorities and Legislative Output, 1917-2010 \label{tabsupermaj}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0)) nomtitles replace
 
estimates clear

**Deficit Spending


gen lag_deficit_unif = unified_g * lag_deficit
label var lag_deficit_unif "Unified Government x Deficit (Lagged)"

local spec1 unified_g lag_deficit lag_deficit_unif
local spec2 `spec1' i.period

forvalues n = 1(1)2{
xi: reg pub_acts `spec`n'' if year>=1901, robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'' if year>=1901, robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/deficit_table.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g lag_deficit lag_deficit_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, the Budget Deficit and Legislative Output, 1901-2010 \label{tabdeficit}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace
 
esttab pub* sig* using "figs_ssh/deficit_table.csv", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g lag_deficit lag_deficit_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, the Budget Deficit and Legislative Output, 1901-2010 \label{tabdeficit}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0)) nomtitles replace
 
estimates clear

*Centrality and Time in Session

gen hs_centralized = (house_lead_ctrl ==1 & sen_lead_ctrl==1)
replace hs_centralized = . if house_lead_ctrl==.

label var hs_centralized "House & Senate Leadership Centralization"

local spec1 unified_g days i.period
local spec2 unified_g hs_centralized i.period
local spec3 unified_g house_lead_ctrl house_caucus sen_lead_ctrl i.period

forvalues n = 1(1)3{
xi: reg pub_acts `spec`n'', robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'', robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/centrality_days_table.tex", b(%9.2f) label indicate("Time Period FEs = _Iperiod_3") coeflabels(_cons "Constant") ///
keep(unified_g days hs_centralized house_lead_ctrl house_caucus sen_lead_ctrl) addnotes("Robust Standard Errors; Data on Centralization covers 52nd Congress onward." ) r2 se compress title("Divided/Unified Government, Days in Session, Centralization, and Legislative Output \label{tabdays}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace
 
esttab pub* sig* using "figs_ssh/centrality_days_table.csv", b(%9.2f) label indicate("Time Period FEs = _Iperiod_3") coeflabels(_cons "Constant") ///
keep(unified_g days hs_centralized house_lead_ctrl house_caucus sen_lead_ctrl) addnotes("Robust Standard Errors; Data on Centralization covers  52nd Congress onward." ) r2 se compress title("Divided/Unified Government, Days in Session, Centralization, and Legislative Output \label{tabdays}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 1 0 0)) nomtitles replace
 
estimates clear
